<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>login</title>
  <link rel="stylesheet" href="lib/css/animate.css">
  <link rel="stylesheet" href="css/login/signin.css">
  <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>

<body>

  <body>
    <div class="container">
      <form class="form-signin" id="form">
        <h2 class="form-signin-heading">请登录</h2>
        <label for="inputEmail" class="sr-only">用户名</label>
        <input type="username" name="nickName" id="inputNickName" class="form-control" placeholder="请输入账号" required autocomplete="off"
          autofocus>
        <label for="inputPassword" class="sr-only">密码</label>
        <input autocomplete="off" type="password" name="password" id="inputPassword" class="form-control" placeholder="请输入密码" required>
        <button class="btn btn-lg btn-primary btn-block" type="submit">登录</button>
      </form>
    </div> <!-- /container -->
    <script src="lib/js/jquery-1.12.4.js"></script>
    <script>
      $(function () {
        $('.btn-block').on('click', function (e) {
          $(this).parent()[0].className += " animate__animated animate__hinge";
          e.preventDefault();
          var nickName = $('#inputNickName')[0].value.trim()
          var password = $('#inputPassword')[0].value.trim()
          console.log(nickName)
          console.log(password)
          $.ajax({
            url: '/pages/login',
            type: 'post',
            data: JSON.stringify({
              nickName: nickName,
              psw: password
            }),
            dataType: 'json',
            contentType:'application/json;charset=UTF-8',
            success: function (res) {
              console.log(res)
              if (res.nickName) {
                window.alert('欢迎'+ res.nickName)
                // 将当前登录用户记录到本地缓存
                localStorage.setItem('userMessage',JSON.stringify(res));
                // self.location = 'index.html?nickName=' + res.nickName + '&name=' + res.name + '&actor=' +
                //   res.actor
                self.location = 'index.html'
              } else {
                var err = res.error
                window.alert(err)
              }
            }
          })
        })
      })
    </script>
    <script src="lib/js/bootstrap.js"></script>
    <script src="js/login/login.js"></script>

    <script src="lib/js/mock.js"></script>
    <script src="mock/login.js"></script>
  </body>
</body>

</html>